﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Odbc;

namespace Test_crystal_report
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }





        private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
        {
            TableLogOnInfos mytableloginfos = new TableLogOnInfos();
            mytableloginfos = crystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
            {
                myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
            }

        }
        private void button1_Click(object sender, EventArgs e)
        {



            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;

        cryRpt.Load("CrystalReport2.rpt");

         //   cryRpt.Load("D:\\Google Drive\\Google Drive\\Code\\Test\\Test_crystal report\\Test_crystal report\\Test_crystal report\\CrystalReport2.rpt");

            crConnectionInfo.ServerName = "192.168.1.210";
            crConnectionInfo.DatabaseName = "TestDB";
            crConnectionInfo.UserID = "dev01";
            crConnectionInfo.Password = "password";

            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }
            
            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();

            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = dateTimePicker1.Value;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["punDate2"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);




            //ParameterFieldDefinitions crParameterFieldDefinitions2;
            //ParameterFieldDefinition crParameterFieldDefinition2;
            //ParameterValues crParameterValues2 = new ParameterValues();

            //ParameterDiscreteValue crParameterDiscreteValue2 = new ParameterDiscreteValue();

            //crParameterDiscreteValue2.Value = textBox1.Text;
            //crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields;
            //crParameterFieldDefinition2 = crParameterFieldDefinitions2["FlightNo2"];
            //crParameterValues2 = crParameterFieldDefinition2.CurrentValues;

            //crParameterValues2.Clear();
            //crParameterValues2.Add(crParameterDiscreteValue);
            //crParameterFieldDefinition.ApplyCurrentValues(crParameterValues2);



            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();



        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //ConnectionInfo myConnectionInfo = new ConnectionInfo();

            //myConnectionInfo.ServerName = "192.168.1.210";
            //myConnectionInfo.DatabaseName = "TestDB";
            //myConnectionInfo.UserID = "dev01";
            //myConnectionInfo.Password = "password";
            //setDBLOGONforREPORT(myConnectionInfo);
         
        }

       
    }
}
